package com.example.androidproject.net;

import com.google.gson.Gson;

import java.io.File;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

public class RequestBodyUtils {


    public static RequestBody jsonBody(Object o){
        Gson gson = new Gson();
        String postInfoStr = gson.toJson(o);
        RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"),postInfoStr);
        return body;
    }

    public static MultipartBody.Part jsonImgBody(String localPath){
        File file = new File(localPath);
        RequestBody requestFile = RequestBody.create(MediaType.parse("image/jpeg"), file);
        MultipartBody.Part body = MultipartBody.Part.createFormData("file",file.getName(),requestFile);
        return body;
    }
}
